package com.mi.controller;

import com.alibaba.dubbo.config.annotation.Reference;
import com.mi.entity.*;
import com.mi.service.Service_PointService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Controller
public class ServiceController {

    @Reference(check = false)
    Service_PointService service_pointService;


    @RequestMapping("jumpServiceSupport")
    public String jumpService(){
        return "service";
    }

//    @RequestMapping("jumpServiceAddress")
//    public String jumpServicePoint(){
//        return "servicepoint";
//    }


    @RequestMapping("jumpServiceAddress")
    public String queryServicePoint(HttpServletRequest request){
        List<ServicePointEntity> servicePointEntities = service_pointService.queryServicePoint();
        System.out.println("服务地址个数："+servicePointEntities.size());
        System.out.println("服务地址："+servicePointEntities);

        request.setAttribute("services",servicePointEntities);

        return "servicepoint";
    }



    @RequestMapping("jumpRepair")
    public String jumpToRepair(){

        return "redirect:serviceRepair";
    }


    @RequestMapping("serviceRepair")
    public String toserviceRepair(){
        return "repair";
    }


    @RequestMapping("torepair")
    @ResponseBody
    public String inserRepair(RepairEntity repairEntity, HttpServletRequest request){

        boolean b = service_pointService.insertRepair(repairEntity);
        if(b){
            return "success";
        }
        else {
            return "fail";
        }
    }


    //资料索取
    @RequestMapping("jumptoDataRequest")
    public String toDataRequest(){
        return "redirect:dataRequest";
    }
    @RequestMapping("dataRequest")
    public String dataRequest(){
        return "requestinfo";
    }

    @RequestMapping("toRequestInfo")
    @ResponseBody
    public String requestin(DataRequestEntity dataRequestEntity,HttpServletRequest request){
        String companyOrHospital = dataRequestEntity.getCompanyOrHospital();
        System.out.println("公司或者医院："+companyOrHospital);
        boolean result = service_pointService.insertDataRequest(dataRequestEntity);
        if(result){
            return "success";
        }
        else {
            return "fail";
        }
    }


    //资料索取
    @RequestMapping("jumptoComplainSuggest")
    public String jumpComplaintSuggest(){
        return "redirect:jumpComplaintAndSuggest";
    }
    @RequestMapping("jumpComplaintAndSuggest")
    public String jumpToComplaintAndSuggest(){
        return "complaintSuggest";
    }

    /**
     * 添加投诉建议
     * @param complaintSuggestEntity
     * @return
     */
    @RequestMapping("ToComplaintSuggest")
    @ResponseBody
    public String ToComplaintSuggest(ComplaintSuggestEntity complaintSuggestEntity){
        boolean result = service_pointService.insertComplaintSuggestService(complaintSuggestEntity);
        if (result){
            return "success";
        }else {
            return "fail";
        }

    }

//    @RequestMapping("jumptopatner")
//    public String jumptoquerypartner(){
//        return "redirect:toQueryPatner";
//    }


    /**
     * 查询合作伙伴
     * @param pt
     * @param request
     * @return
     */
    @RequestMapping("toQueryPatner")
    public String queryPatner(PartnerEntity pt,HttpServletRequest request){
        MyPages<PartnerEntity> partners = service_pointService.queryPartnerService(pt);
        System.out.println("查到的信息为："+partners);
        request.setAttribute("myPatners",partners);
        return "jumpartner";
    }


}
